import { fileURLToPath, URL } from 'node:url'

import Uni from '@dcloudio/vite-plugin-uni'
import Components from '@uni-helper/vite-plugin-uni-components'
import { WotResolver } from '@uni-helper/vite-plugin-uni-components/resolvers'
import UnoCSS from 'unocss/vite'
import AutoImport from 'unplugin-auto-import/vite'
import { defineConfig } from 'vite'

const UniAlias = (Uni as any).default || Uni

export default async () => {
  return defineConfig({
    resolve: {
      alias: {
        '@': fileURLToPath(new URL('./src', import.meta.url)),
      },
    },
    plugins: [
      Components({
        dts: false,
        resolvers: [WotResolver()],
      }),
      // https://github.com/uni-helper/plugin-uni
      UniAlias(),
      AutoImport({
        imports: [
          'vue',
          'uni-app',
        ],
        dts: 'src/types/auto-imports.d.ts',
        vueTemplate: false,
      }),
      // https://github.com/antfu/unocss
      // see unocss.config.ts for config
      UnoCSS(),
    ],

  })
}
